import { debounce, throttle } from 'lodash';
import { message } from 'antd';

const showMessageDelayTime = 500;
// 用户体验相关，主要用于拦截http错误拦截，自定义显示错误信息。
export const showErrorMessageDebounce = debounce(
  (messageStr, callback?: any) => {
    if (callback) callback();
    message.error(messageStr);
  },
  showMessageDelayTime,
);

export const showSuccessMessageDebounce = debounce(
  (messageStr, callback?: any) => {
    if (callback) callback();
    message.success(messageStr);
  },
  showMessageDelayTime,
);

/**
 * 节流 成功
 */
export const showSuccessMessageThrottle = throttle(
  (messageStr, callback?: any) => {
    if (callback) callback();
    message.success(messageStr, 1);
  },
  showMessageDelayTime,
);

export const showErrorMessageThrottle = throttle(
  (messageStr, callback?: any) => {
    if (callback) callback();
    message.error(messageStr, 2);
  },
  showMessageDelayTime,
);
